<?php 
/**
 * ... ...
 * ... ...
 *
 */ 


JCAT_Package::ImportClass('JCAT_ViewGtk',JCAT::PACKAGE_MVCGTK) ;
JCAT_Package::ImportInterface('JCAT_IViewForm',JCAT::PACKAGE_MVC) ;


/**
 * 视图类 DBDocumentView 
 *
 * @access public
 */
class DBDocumentView 
	//<<[UnmodifiableBlock.Start]::Extends And Implements::>>//
	extends JCAT_ViewGtk
	implements JCAT_IViewForm
	//<<[UnmodifiableBlock.End]::Extends And Implements::>>// 
{
	
	/**
	 * 构造函数 
	 *
	 * @access	public
	 * @param	$aParent	JCAT_IViewContainer		视图的父对象(父视图 或 控制器)。注意：视图不应单独存在，必须有一个父对象！ 
	 * @return	void
	 */
	public function DBDocumentView(DBDocument $aParent)
	{
		// 调用父类构造函数 
		//<<[UnmodifiableBlock.Start]::Call Parent Construct::>>//
		$this->JCAT_ViewGtk('DBDocumentView','template.DBDocumentView.glade','DBDocumentView',$aParent) ;
		//<<[UnmodifiableBlock.End]::Call Parent Construct::>>// 

		$this->Initialize() ;	
	}

	/**
	 * 初始化 视图 
	 *
	 * @access	public
	 * @return	void
	 */
	public function Initialize()
	{
		$sCurrentDirectory = dirname(__FILE__).'/' ;
		//<<[UnmodifiableBlock.Start]::UICtrl Children::>>//
		// 载入UI控件
		$sCurrentDirectory = dirname(__FILE__).'/' ;
		$this->AddUICtrl(JCAT_Package::ImportInstance($sCurrentDirectory.'Instance.UICtrls/instance.MainTable.php'),'MainTable') ;
		$this->AddUICtrl(JCAT_Package::ImportInstance($sCurrentDirectory.'Instance.UICtrls/instance.MainKey.php'),'MainKey') ;
		JCAT_Package::ImportClass('TreeUseColumns',$sCurrentDirectory.'Instance.UICtrls/class.TreeUseColumns.php') ;
		$this->AddUICtrl(new TreeUseColumns(),'UseColumns') ;
		//<<[UnmodifiableBlock.End]::UICtrl Children::>>// 
		
		
		// 创建并添加子视图
		$sCurrentDirectory = dirname(__FILE__).'/' ;
		JCAT_Package::ImportClass('DBTableLinkView',$sCurrentDirectory.'DBTableLink/class.DBTableLinkView.php') ;
		$this->AddView(new DBTableLinkView($this)) ;
		

		$this->AddView(new DBTableLinkView($this,'DBQueryConditionView','QueryCondition',false)) ;
		
		// 在此加入其它初始化代码 
	 	// TODO ... ...
	}

	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @param	$aDocument	JCAT_IDocument	What's this Parameter ?
	 * @return	old_var
	 */
	public function SetDocument( JCAT_IDocument $aDocument )
	{
		// 将文档 设置给 子视图
		$aView = $this->GetView('DBTableLinkView') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aView,'JCAT_IView') ;
		$aView->SetDocument($aDocument) ;
		
		$aView = $this->GetView('DBQueryConditionView') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aView,'JCAT_IView') ;
		$aView->SetDocument($aDocument) ;
		
		// 
		parent::SetDocument($aDocument) ;
	}
	
	/**
	 * 创建主窗体事件 
	 *
	 * @access	protected
	 * @return	void
	 */
	 protected function OnInitView()
	 {
	 	// $this->aTableColumnModel = $aUICtrl
	 }


	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnConnectDB()
	 {
		// 连接数据库
	 	$aController = new DBConnect() ;
	 	$aDB = $aController->MainRun() ;//$aDB = new JCAT_DB() ;
	 	
	 	if($aDB!==null)
	 	{	 		
	 		$this->arrTableAndColumns = array() ;
	 		$aConnect = $aDB->GetConnect() ;
	 	
	 		// 反射 数据库结构
	 		$arrTables = $aConnect->GetTableNameList() ;
	 		$arrTableAndColumns = array() ;
	 		
	 		// 主数据表菜单
			$aUICtrlMainTable = $this->GetUICtrl('MainTable') ;
			JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlMainTable,'JCAT_IUICtrl') ;
			$aUICtrlMainTable->ClearOptions() ;
			
	 		foreach ($arrTables as $sTableName)
	 		{
	 			$aUICtrlMainTable->AddOption($sTableName) ;

	 			$this->arrTableAndColumns[$sTableName] 
	 					= $aConnect->GetColumnNameList($sTableName) ;
	 			
	 			if( empty($this->arrTableAndColumns[$sTableName]) )
	 			{
	 				echo $aDB ->GetError() ;
	 			}
	 			else 
	 			{
		 			//foreach ($this->arrTableAndColumns[$sTableName] as $sColumnName)
		 			//{
		 			//}
	 			}
	 		}
	 		
	 		
	 		// “使用字段” 视图
	 		$aUICtrlUseColumns = $this->GetUICtrl('TreeUseColumns') ;
	 		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlUseColumns,'JCAT_IUICtrl') ;
	 		
	 		$aUICtrlUseColumns->SetColumns($this->arrTableAndColumns) ;
	 		
	 		
	 		// 将 表/字段 结构 传递给  子视图 ::::::
	 		$aDBTableLinkView = JCAT_View::GetViewByGlobalName('DBTableLinkView') ;
	 		$aDBTableLinkView->SetTableColumns($this->arrTableAndColumns) ;
	 		
	 		$aDBQueryConditionView = JCAT_View::GetViewByGlobalName('DBQueryConditionView') ;
	 		$aDBQueryConditionView->SetTableColumns($this->arrTableAndColumns) ;
	 		
	 		
	 		
	 		// 设置状态
	 		$this->SetConnected(true);
	 	}
	 	
	 	else
	 	{
	 		$this->SetConnected(false);
	 	}
	 }

	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnMainTableChanged()
	 {
		$aUICtrlMainTable = $this->GetUICtrl('MainTable') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlMainTable,'JCAT_IUICtrl') ;
		
		$aUICtrlMainKey = $this->GetUICtrl('MainKey') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlMainKey,'JCAT_IUICtrl') ;
		$aUICtrlMainKey->ClearOptions() ;
	 	
		$sTable = $aUICtrlMainTable->GetExchangeData() ;
		
		if( isset($this->arrTableAndColumns[$sTable]) )
		{
			foreach ($this->arrTableAndColumns[$sTable] as $sColumnName)
			{
				$aUICtrlMainKey->AddOption($sColumnName) ;
			}
		}
	 }
	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function SetConnected( $bConnected )
	 {
	 	$wndConnectState = $this->GetChildWidget('ImgConnectState') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($wndConnectState,'GtkImage') ;
	 	
	 	if($bConnected)
	 	{
	 		$wndConnectState->set_from_stock(Gtk::STOCK_CONNECT,4) ;
	 	}
	 	else 
	 	{
	 		$wndConnectState->set_from_stock(Gtk::STOCK_DISCONNECT,4) ;	 		 	
	 	}
	 } 

	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnBeforeSwitchPage(GtkNotebook $wndNotebook, $aPointer, $nPageNum)
	 {$aPointer ;$nPageNum ;
	 	$this->nLastTab = $wndNotebook->get_current_page();
	 }
	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnAfterSwitchPage(GtkNotebook $wndNotebook, $aPointer, $nPageNum)
	 {$aPointer ;
	 	if( $nPageNum==3 )
	 	{
	 		$wndNotebook->set_current_page($this->nLastTab);
	 	}
	 }
	 
	 
	/**
	 * 
	 * 
	 * @access	private
	 * @var		array
	 */
	private $arrTableAndColumns = array() ;
	
	
	/**
	 * 
	 * 
	 * @access	private
	 * @var		GtrTreeStroe
	 */	
	private $aTableColumnModel ;
}

?><?
/**
 * [注意!!]
 *	以下内容由 JCAT PHP Toolbox 自动维护，手动更改的内容会被 JCAT PHP Toolbox 抹除，
 *	同时还可能破坏格式，导致 JCAT PHP Toolbox 无法正常读取。
 */
/*<<[UnmodifiableBlock.Start]::Coder Dialog Data::>>&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
<<{{DocumentClass:ViewGtkDoc}}>>
eCVEQSU4RFUlREIlOTIlREFGJTEwJTdET1UlM0UlMjIlN0MlODAlMTElQjclRjVadiVCOSU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